/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.uml_generator.model.impl;

import com.genia.toolbox.uml_generator.model.AbstractJavaObject;

/**
 * implementation of {@link AbstractJavaObject}.
 */
public abstract class AbstractJavaObjectImpl
    extends AbstractObjectImpl
    implements AbstractJavaObject
{

  /**
   * returns the original object if the current object is decorated.
   * 
   * @return the original object if the current object is decorated *
   * @see com.genia.toolbox.uml_generator.model.impl.AbstractObjectImpl#getUndecoraredObject()
   */
  @Override
  public AbstractJavaObject getUndecoraredObject()
  {
    return (AbstractJavaObject) super.getUndecoraredObject();
  }



  /**
   * returns the default value of the object.
   * 
   * @return the default value of the object
   * @see com.genia.toolbox.uml_generator.model.AbstractJavaObject#getDefaultValue()
   */
  public String getDefaultValue()
  {
    return "null";
  }



  /**
   * returns the qualified name to use in the hibernate mapping file.
   * 
   * @return the qualified name to use in the hibernate mapping file
   * @see com.genia.toolbox.uml_generator.model.AbstractJavaObject#getHibernateQualifiedName()
   */
  public String getHibernateQualifiedName()
  {
    return getQualifiedName();
  }

  /**
   * the package of the object.
   */
  private String packageName;



  /**
   * returns the name of the package of this object.
   * 
   * @return the name of the package of this object
   * @see com.genia.toolbox.uml_generator.model.AbstractJavaObject#getPackageName()
   */
  public String getPackageName()
  {
    return packageName;
  }



  /**
   * setter for the packageName property.
   * 
   * @param packageName
   *          the packageName to set
   * @see com.genia.toolbox.uml_generator.model.AbstractJavaObject#setPackageName(java.lang.String)
   */
  public void setPackageName(String packageName)
  {
    if (packageName == null || "java.lang".equals(packageName)) {
      packageName = "";
    }
    this.packageName = packageName;
  }



  /**
   * returns the qualified name of this object.
   * 
   * @return the qualified name of this object
   * @see com.genia.toolbox.uml_generator.model.AbstractJavaObject#getQualifiedName()
   */
  public String getQualifiedName()
  {
    return getQualifiedName(getPackageName(), getName());
  }



  /**
   * construct a qualified name from the package name and the object name.
   * 
   * @param packageName
   *          the package name
   * @param name
   *          the name of the object
   * @return a qualified name from the package name and the object name
   */
  protected String getQualifiedName(String packageName, String name)
  {
    if ("".equals(packageName)) {
      return name;
    }
    return packageName + "." + name;
  }



  /**
   * return the object type that represents this type. For non primitive type,
   * it is always itself, for primitive type it is the correct wrapper.
   * 
   * @return the object type that represents this type
   */
  public AbstractJavaObject getObject()
  {
    return this;
  }

}
